<template>
	<view class="container">
		<!-- <view class="group_item">
			<view class="group_title">
				<span style="color: red;">*</span>小区
			</view>
			<picker mode="selector" :value="selectCommunity" :range="communities" @change="bindCommunityChange" class="picker_class">
				<view class="uni-input">请选择小区</view>
			</picker>
		</view> -->
		<view class="group_item">
			<view class="group_title">
				<span style="color: red;">*</span>标题
			</view>
			<input type="text" v-model="titleInput" placeholder="请输入标题" class="picker_class" />
		</view>
		<view class="group_item">
			<view class="group_title">
				<span style="color: red;">*</span>内容
			</view>
			<textarea maxlength="140" v-model="contentInput" type="text" placeholder="请输入内容" class="picker_content_class" />
			</view>
		<view class="group_item1">
			<view class="group_title1">
				图片
			</view>
			<view>
				<robby-image-upload v-model="imageUrlList" fileKeyName="files" :header="header" :formData="formData"
					:server-url="uploadUrl" :showUploadProgress="true" limit="6"></robby-image-upload>
			</view>
		</view>
		<button type="primary" class="button_class" @click="msgSecCheck">发布</button>
	</view>
</template>

<script>
	import robbyImageUpload from "@/components/robby-image-upload/robby-image-upload";
	import {
		mapState,
		mapMutations
	} from 'vuex';
	export default {
		data() {
			return {
				titleInput: '',
				contentInput: '',
				communityId: this.$api.util.getAreaCode(),
				communities: [
					"平安小区", "七里小区", "盛世嘉苑"
				],

				imageUrlList: [],
				header: {
					appId: uni.getStorageSync("appId")
				},
				formData: {},
				uploadUrl: this.$api.request.apiBaseUrl + 'uploadSingleFile'
			}
		},
		onLoad() {

		},
		computed: {
			...mapState(['hasLogin', 'userInfo'])
		},
		methods: {
			navTo(path) {
				uni.navigateTo({
					url: path
				})
			},
			// 对接微信内容安全API（文本）
			msgSecCheck(){
				if (this.titleInput == "") {
					uni.showToast({
						title: '请填写标题',
						icon: 'none',
						duration: 2000
					});
					return
				}
				if (this.contentInput == "") {
					uni.showToast({
						title: '请填写内容',
						icon: 'none',
						duration: 2000
					});
					return
				}
				
				let msg = this.titleInput + this.contentInput;
				let params = {
					content:msg,
					appId:uni.getStorageSync("appId")
				}
				this.$api.request.WXMsgSecCheck(params,(res) => {
					console.log(res)
					if(res.body.status.statusCode == 0){
						this.addNeighborShare()
					}else if(res.body.status.statusCode == 2){
						this.$api.msg(res.body.status.errorDesc)
					}else{
						this.$api.msg("系统错误")
					}
				})
			},
			addNeighborShare() {
				let UserID = this.userInfo.userUuid
				console.log(UserID)
			
				let params = {
					"title": this.titleInput,
					"content": this.contentInput,
					"imageUrl": this.imageUrlList,
					"userUuid": UserID,
					"areaCode": this.communityId
				}
				this.$api.request.addNeighborShare(params, (res) => {
					console.log(res)
					if (res.body.status.statusCode == 0) {
						uni.showToast({
							title: "发布成功",
						})
						uni.navigateBack()
					} else {
						uni.showToast({
							title: "发布失败",
						})
					}
				})
			}
		},
		components: {
			robbyImageUpload
		}
	}
</script>

<style>
	.container {
		width: 100%;
		background-color: #FBFBFB;
		overflow: hidden;
	}

	.group_item {
		width: 100%;
		padding: 0upx 30upx;
		margin: 10upx 0;
		display: flex;
		flex-direction: row;
		background-color: white;
	}

	.group_item1 {
		width: 100%;
		padding: 10upx 30upx;
		margin: 10upx 0;
		background-color: white;
		overflow: hidden;
	}

	.group_title1 {
		width: 100upx;
		font-size: 30upx;
		font-weight: bold;
	}

	.group_title {
		width: 100upx;
		padding-top: 30upx;
		/* height: 100upx; */
		/* line-height: 100upx; */
		font-size: 30upx;
		font-weight: bold;
	}

	.picker_class {
		width: 100%;
		height: 100upx;
		line-height: 100upx;
		margin-left: 30upx;
		font-size: 28upx;
		padding-left: 10upx;
	}

	.picker_content_class {
		width: 100%;
		height: 200upx;
		margin-top: 30upx;
		margin-left: 30upx;
		font-size: 28upx;
		padding-left: 10upx;
	}

	input {
		padding-left: 10upx;
	}

	.button_class {
		position: fixed;
		bottom: 40upx;
		margin-top: 20upx;
		width: 80%;
		margin-left: 10%;
		height: 80upx;
		line-height: 80upx;
		border-radius: 40upx;
		background-color: #1DA3EE !important;
		color: white
	}
</style>
